home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Graphics / Gnuplot / Source / term / fig.trm < prev    next >
Encoding:
Text File  |  1993-03-02  |  7.4 KB  |  279 lines

  1. /*
  2.  * $Id: fig.trm%v 3.38.2.74 1993/02/19 01:11:43 woo Exp woo $
  3.  *
  4.  */
  5.  
  6. /* GNUPLOT - fig.trm */
  7. /*
  8.  * Copyright (C) 1990 - 1993
  9.  *
  10.  * Permission to use, copy, and distribute this software and its
  11.  * documentation for any purpose with or without fee is hereby granted,
  12.  * provided that the above copyright notice appear in all copies and
  13.  * that both that copyright notice and this permission notice appear
  14.  * in supporting documentation.
  15.  *
  16.  * Permission to modify the software is granted, but not the right to
  17.  * distribute the modified code.  Modifications are to be distributed
  18.  * as patches to released version.
  19.  *
  20.  * This software  is provided "as is" without express or implied warranty.
  21.  *
  22.  * This file is included by ../term.c.
  23.  *
  24.  * This terminal driver supports:
  25.  *  Fig graphics language
  26.  *
  27.  * AUTHORS
  28.  *  Micah Beck, David Kotz
  29.  *
  30.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  31.  *
  32.  */
  33.  
  34. #ifdef MSDOS
  35. #define long int
  36. #endif /* MSDOS */
  37.  
  38. /*
  39.  * Original for Fig code output by Micah Beck, 1989
  40.  * Department of Computer Science, Cornell University
  41.  * Updated by David Kotz for gnuplot 2.0
  42.  * More efficient output Ian by Dall
  43.  */
  44. #include "object.h"                     /* from the TransFig distribution */
  45. #define FIG_DEFAULT (-1)
  46. #define FIG_ROMAN_FONT (0)
  47.  
  48. #ifndef FIG_RES
  49. /* Must be 80 for the Fig editor, but may be increased if used
  50.  * only by TransFig filters.
  51.  * Represents resolution per inch.
  52.  */
  53. #define FIG_RES         80
  54. #endif
  55.  
  56. #define FIG_COORD_SYS   2
  57.  
  58. #define FIG_MAGIC       "#FIG 1.4-TFX"
  59. #define FIG_HTIC        (5*FIG_RES/80)
  60. #define FIG_VTIC        (5*FIG_RES/80)
  61. #define FIG_FONT_S      FIG_DEFAULT
  62. #define FIG_HCHAR       (6*FIG_RES/80) /* Change if FIG_FONT_S is changed */
  63. #define FIG_VCHAR       (12*FIG_RES/80) /* Change if FIG_FONT_S is changed */
  64. #define FIG_ARROW_WIDTH FIG_HTIC
  65. #define FIG_ARROW_HEIGHT FIG_HTIC
  66.  
  67. static long FIG_xbase = FIG_RES/2;
  68. static long FIG_ybase = FIG_RES/2;
  69.  
  70. static long FIG_posx;
  71. static long FIG_posy;
  72. static int FIG_poly_vec_cnt;
  73. enum FIG_poly_stat {FIG_poly_new, FIG_poly_part};
  74. static enum FIG_poly_stat FIG_polyvec_stat;
  75. /* 5 inches wide by 3 inches high */
  76. #define FIG_XMAX (5 * FIG_RES)
  77. #define FIG_YMAX (3 * FIG_RES)
  78.  
  79. #define FIG_XOFF (FIG_RES/4)
  80. #define FIG_YOFF (FIG_RES/4)
  81.  
  82. static int FIG_type;            /* negative types use real lines */
  83. static float FIG_spacing;       /* length of dash or dot spacing */
  84. static int FIG_justify;         /* Fig justification T_*_JUSTIFIED */
  85. static float FIG_angle;         /* Fig text angle 0=horiz, Pi/2=vert */
  86.  
  87. #define FIG_POINT_TYPES POINT_TYPES /* we use the same points */
  88.  
  89. static
  90.   FIG_poly_clean(stat)
  91. enum FIG_poly_stat stat;
  92. {
  93.   if(stat == FIG_poly_part)
  94.         fprintf(outfile, " 9999 9999\n");
  95.   FIG_polyvec_stat = FIG_poly_new;
  96. }
  97.  
  98. FIG_init()
  99. {
  100.     FIG_posx = FIG_posy = 0;
  101.     FIG_polyvec_stat = FIG_poly_new;
  102.     FIG_linetype(-1);
  103.     FIG_justify_text(LEFT);
  104.     FIG_text_angle(0);
  105.  
  106.     fprintf(outfile, "%s\n", FIG_MAGIC);
  107.     fprintf(outfile, "%d %d\n", FIG_RES, FIG_COORD_SYS);
  108. }
  109.  
  110.  
  111. FIG_graphics()
  112. {
  113.     FIG_posx = FIG_posy = 0;
  114.     FIG_polyvec_stat = FIG_poly_new;
  115.     /* there is no way to have separate pictures in a FIG file */
  116. }
  117.  
  118.  
  119. FIG_text()
  120. {
  121.     /* there is no way to have separate pictures in a FIG file */
  122.     FIG_poly_clean(FIG_polyvec_stat);
  123.     FIG_posx = FIG_posy = 0;
  124.     fflush(outfile);
  125. }
  126.  
  127.  
  128. /* Line types for FIG work like this:
  129.  *  -2 : solid (border)
  130.  *  -1 : dashed 4 (axes)
  131.  *   0 : solid (first curve)
  132.  *   1 : dotted 3
  133.  *   2 : dashed 3
  134.  *   3 : dotted 6
  135.  *   4 : dashed 6
  136.  *   ... ...
  137.  */
  138.  
  139. FIG_linetype(linetype)
  140.         int linetype;                   /* expect linetype >= -2 */
  141. {
  142.     int last_FIG_type = FIG_type;
  143.     int last_FIG_spacing = FIG_spacing;
  144.     switch (linetype) {
  145.            case 0:
  146.            case -2: {
  147.                   FIG_type = 0; /* solid line */
  148.                   FIG_spacing = 0.0;
  149.                   break;
  150.            }
  151.            case -1: {
  152.                   FIG_type = 1; /* dashed */
  153.                   FIG_spacing = 4.0; /* dash length */
  154.                   break;
  155.            }
  156.            default: {
  157.                   linetype = abs(linetype); /* shouldn't be negative anyway */
  158.                   /* now linetype >= 1 */
  159.                   FIG_type = linetype % 2 + 1; /* dotted, dashed, ... */
  160.                   FIG_spacing = (linetype+1) / 2 * 3;
  161.                   break;
  162.            }
  163.     }
  164.     if (FIG_type != last_FIG_type || FIG_spacing != last_FIG_spacing)
  165.       FIG_poly_clean(FIG_polyvec_stat);
  166. }
  167.  
  168. FIG_move(x,y)
  169.         unsigned int x,y;
  170. {
  171.     int last_FIG_posx = FIG_posx;
  172.     int last_FIG_posy = FIG_posy;
  173.     FIG_posx = x;
  174.     FIG_posy = y;
  175.     if (FIG_posx != last_FIG_posx || FIG_posy != last_FIG_posy)
  176.           FIG_poly_clean(FIG_polyvec_stat);
  177. }
  178.  
  179.  
  180. FIG_vector(ux,uy)
  181.      unsigned int ux,uy;
  182. {
  183.   int x=ux, y=uy;
  184.  
  185.   if (FIG_polyvec_stat != FIG_poly_part)
  186.     {
  187.       fprintf(outfile, "%d %d %d %d %d %d %d %d %6.3f  %d %d\n",
  188.               O_POLYLINE, T_POLYLINE,
  189.               FIG_type, 1, FIG_DEFAULT, FIG_DEFAULT, FIG_DEFAULT, FIG_DEFAULT, FIG_spacing,
  190.               0, 0);
  191.       fprintf(outfile, "%d %d",
  192.               FIG_XOFF + FIG_posx, FIG_YMAX + FIG_YOFF - FIG_posy);
  193.       FIG_poly_vec_cnt = 1;
  194.       FIG_polyvec_stat = FIG_poly_part;
  195.     }
  196.   fprintf(outfile, " %d %d",
  197.           FIG_XOFF +  x, FIG_YMAX + FIG_YOFF-y);
  198.   FIG_poly_vec_cnt++;
  199.   if (FIG_poly_vec_cnt > 50)
  200.     FIG_poly_clean(FIG_polyvec_stat);
  201.  
  202.   FIG_posx = x;
  203.   FIG_posy = y;
  204. }
  205.  
  206.  
  207. FIG_arrow(sx, sy, ex, ey, head)
  208.         int sx, sy;     /* start coord */
  209.         int ex, ey;     /* end coord */
  210.     TBOOLEAN head;
  211. {
  212.     FIG_poly_clean(FIG_polyvec_stat);
  213.         fprintf(outfile, "%d %d %d %d %d %d %d %d %6.3f  %d %d\n",
  214.                 O_POLYLINE, T_POLYLINE,
  215.                 FIG_type, 1, FIG_DEFAULT, FIG_DEFAULT, FIG_DEFAULT, FIG_DEFAULT, FIG_spacing,
  216.                 head ? 1 : 0, 0);
  217.         /* arrow line */
  218.     if ( head )
  219.             fprintf(outfile, "%d %d %.3f %.3f %.3f\n",
  220.                     0, 0, 1.0,
  221.             (double)FIG_ARROW_WIDTH, (double)FIG_ARROW_HEIGHT);
  222.         fprintf(outfile, "%d %d %d %d 9999 9999\n",
  223.                 FIG_XOFF + sx, FIG_YOFF + FIG_YMAX - sy,
  224.         FIG_XOFF + ex, FIG_YOFF + FIG_YMAX - ey);
  225.  
  226.         FIG_posx = ex;
  227.         FIG_posy = ey;
  228. }
  229.  
  230.  
  231. FIG_put_text(x, y, str)
  232.         int x, y;
  233.         char *str;
  234. {
  235.   if (strlen(str) == 0) return;
  236.   FIG_poly_clean(FIG_polyvec_stat);
  237.     y = y - FIG_VCHAR/2;                /* assuming vertical center justified */
  238.  
  239.     fprintf(outfile, "%d %d %d %d %d %d %d %6.3f %d %d %d %d %d %s\01\n",
  240.                   O_TEXT, FIG_justify,
  241.                   FIG_ROMAN_FONT, FIG_FONT_S, FIG_DEFAULT, FIG_DEFAULT, FIG_DEFAULT, FIG_angle,
  242.                   FIG_DEFAULT, FIG_VCHAR, FIG_HCHAR*strlen(str), FIG_XOFF + x,
  243.         FIG_YMAX + FIG_YOFF-y, str);
  244. }
  245.  
  246. int FIG_justify_text(mode)
  247.         enum JUSTIFY mode;
  248. {
  249.     switch(mode) {
  250.            case LEFT: FIG_justify = T_LEFT_JUSTIFIED; break;
  251.            case CENTRE: FIG_justify = T_CENTER_JUSTIFIED; break;
  252.            case RIGHT: FIG_justify = T_RIGHT_JUSTIFIED; break;
  253.            /* shouldn't happen */
  254.            default: FIG_justify = T_LEFT_JUSTIFIED; break;
  255.     }
  256.     return (TRUE);
  257. }
  258.  
  259. int FIG_text_angle(angle)
  260.         int angle;
  261. {
  262.     if (angle)
  263.          FIG_angle = Pi / 2.0;  /* vertical is pi/2 radians */
  264.     else
  265.          FIG_angle = 0.0;               /* horizontal */
  266.     return (TRUE);
  267. }
  268.  
  269. FIG_reset()
  270. {
  271.     FIG_poly_clean(FIG_polyvec_stat);
  272.     FIG_posx = FIG_posy = 0;
  273.     fflush(outfile);
  274. }
  275.  
  276. #ifdef MSDOS
  277. #undef long
  278. #endif /* MSDOS */
  279.